/**
 * 
 */
package com.jewaton.auth.commons;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 系统常量
 */
public class SystemContext {
	public static final String WEB_BASE_DIR ="web.base.dir";
	public static final String SPRING_APPLICATION_CONTEXT="applicationContext";
	public static final String CURRENT_ACCOUNT = "current.account";
	public static final String HTTP_REQUEST_MOTHOD = "http.request.method";
	public static final String HTTP_REQUEST = "http.request";
	
	private static ThreadLocal<SystemContext> threadLocal = new ThreadLocal<SystemContext>();
	
	private Map<String, Object> attr = new ConcurrentHashMap<String, Object>(); //new HashMap<String, Object>();
	
	public static SystemContext getContext(){
		SystemContext context = threadLocal.get();
		if(context == null   ){
			context = new SystemContext();
			threadLocal.set(context);
		}
		return context;
	}
	
	public static void destory() {
	    SystemContext context = threadLocal.get();
	    if (context != null) {
	        threadLocal.set(null);
	        context = null;
	    }
	}
	 
	public Object get(String key){
		return attr.get(key);
	}
	
	public void put(String key, Object value){
		attr.put(key, value);
	}
	
}
